/**
 * Created by hejianxian on 15/10/13.
 */
module.exports = {

    getOut: function() {
        cordova.exec(function(result) {},
            function(error) {
                alert("调用失败:" + error);
            },
            "appStore",
            "exit", []);
    },

    getLocation: function(callback) {
        cordova.exec(function(winParam) {
                var location = JSON.parse(winParam);
                callback(location);
            },
            function(error) {
                callback();
            },
            "location",
            "getLocation", []);
    },
    setRfchinaCookies(params, callback) {
        cordova.exec(function(winParam) {
                callback(true);
            },
            function(error) {
                callback()
            },
            "WorkPlus_WebView",
            "setRfchinaCookies", [{
                "domain": params.domain || "",
                "key": params.key || "sso.rfchina.com"
            }]);
    },
    openWebView(params, callback){
        cordova.exec(function(winParam) {
                callback(true);
            },
            function(error) {
                callback();
            },
            "WorkPlus_WebView",
            "openWebView", [{
                "url": params.url,
                "title": params.title
            }]
        );
    },
    getTheme: function(callback) {
        cordova.exec(function(winParam) {
                callback(winParam);
            },
            function(error) {
                callback("调用失败");
            },
            "WorkPlus_Theme",
            "getTheme", []);
    },
    openAuthNormalWebview: function(params, callback) {
        cordova.exec(function(winParam) {
                callback(winParam);
            },
            function(error) {
                callback();
            },
            "WorkPlus_WebView",
            "openWebViewNeedAuth", [{
                "url": params.url,
                "title": params.title
            }]);
    },
    getCurrentUserInfo: function(callback) {
        cordova.exec(function(result) {
                if (result == null) {
                    callback("获取当前用户异常");
                    return;
                }
                // var currentUser = JSON.parse(result);
                callback(result);
            },
            function(error) {
                callback();
            },
            "WorkPlus_Contact",
            "getCurrentUserInfo", []);
    },

    // 获取用户ticket
    getUserTicket: function(callback) {
        cordova.exec(function(result) {
                if (result === null) {
                    callback();
                    return;
                }

                var userTicket = JSON.parse(result);
                callback(userTicket);

            },
            function(error) {
                callback();
            },
            "atwork",
            "getUserTicket", []);
    },

    selectPhoto: function(callback) {
        cordova.exec(function(result) {
                callback(result);
            },
            function(error) {
                alert("选择相册接口调用失败:" + error);
                callback();
            },
            "Images",
            "getImages", []);
    },

    openCamera: function(callback) {
        cordova.exec(function(result) {
                callback(result.success);
            },
            function(error) {
                alert("打开摄像头接口调用失败:" + error);
                callback();
            },
            "associates",
            "takePhoto", []);
    },

    //用于清除压缩的图片
    cleanCompressImage: function() {
        cordova.exec(function(result) {},
            function(error) {
                alert("清除缓存图片接口调用失败:" + error);
            },
            "associates",
            "cleanCompressImage", []);
    }

};